<?php
class Payments_Form_Platnosci extends Zend_Form
{
	/**
	 * @var KontorX_Payments_Platnosci
	 */
	protected $_payments;

	/**
	 * @param KontorX_Payments_Platnosci $platnosci
	 * @return void
	 */
	public function setPayments(KontorX_Payments_Platnosci $platnosci)
	{
		$this->_payments = $platnosci;
	}

	/**
	 * @return KontorX_Payments_Platnosci
	 */
	public function getPayments()
	{
		if (null === $this->_payments)
		{
			throw new Exception('Nie przekazano obiektu płatności');
		}

		return $this->_payments;
	}
/*
<form action="https://www.platnosci.pl/paygw/ISO/NewPayment" method="POST"
  name="payform">
    <input type="hidden" name="pos_id" value="12345">
    <input type="hidden" name="session_id" value="1234565">
    <input type="hidden" name="amount" value="1000">
    <input type="hidden" name="desc" value="Opis płatności">
    <script language=’JavaScript’ type=’text/JavaScript’>
            PlnDrawSelect();
    </script>
    <input type="hidden" name="client_ip" value="123.123.123.123">
    <input type="hidden" name="js" value="0">
    <input type="submit" value="Zapłać poprzez Platnosci.pl">
</form>
*/
	public function init()
	{
		$payments = $this->getPayments();
		$action = $payments->getUrlDlaProcedury(KontorX_Payments_Platnosci::ACTION_NEW);

		$this->setAction($action);
		$this->setName('payform');
		$this->setMethod('POST');

		// pozbycie się zbędnej dekoracji
		$this->addDecorator('FormElements')
                 ->addDecorator('Form');
		$this->setElementDecorators(array(
			'ViewHelper',
			'Description'
		));

		$this->addElement('hidden', 'pos_id', array(
			'value' => $payments->getPosId() 
		));
		$this->addElement('hidden', 'pos_auth_key', array(
			'value' => $payments->getPostAuthKey()
		));
		$this->addElement('hidden', 'session_id', array(
			'value' => $payments->getSessionId()
		));
		$this->addElement('hidden', 'amount', array(
			'value' => $payments->getAmount() 
		));
		$this->addElement('hidden', 'desc', array(
			'value' => $payments->getDesc()
		));
		$this->addElement('hidden', 'street', array(
			'value' => $payments->getStreet()
		));
		$this->addElement('hidden', 'city', array(
			'value' => $payments->getCity()
		));
		$this->addElement('hidden', 'post_code', array(
			'value' => $payments->getPostCode()
		));
		$this->addElement('hidden', 'client_ip', array(
			'value' => $payments->getClientIP()
		));
		$this->addElement('hidden', 'js', array(
			'value' => 0
		));

		$this->addElement('hidden', 'first_name', array(
			'value' => $payments->getFirstName()
		));
		$this->addElement('hidden', 'last_name', array(
			'value' => $payments->getLastName()
		));
		$this->addElement('hidden', 'email', array(
			'value' => $payments->getEmail()
		));

		if (($paymentsTypes = $payments->getPaymentsAvalibleTypes()))
		{
			$this->addElement(new KontorX_Form_Element_Payments('pay_type', array(
				'label' => 'Wybierz formę płatności',
				'paymentsTypes' => $paymentsTypes
			)));
		}
//		 else {
//			$this->addElement('select', 'pay_type', array(
//				'label' => 'Wybierz formę płatności',
//				'multiOptions' => $payments->getPaymentsTypes()
//			));
//		}
		
		
		$this->addElement('submit', 'submit', array(
			'label' => 'Kliknij, by zapłacić za zakupy',
			'description' => 'Zostaniesz teraz przeniesiony do strony platnosci.pl na której będziesz mógł dokonać płatności za dokonane zakupy.'
		));
	}
}